package com.ym.manager.admin.statics;

import com.ym.utils.DateHandler;
import com.ym.utils.ResultUtil;
import com.ym.utils.StringHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Author 但何非
 * @Date 2022/12/13 20:13
 * @ClassName: StaticsController
 * @Description: 平台统计
 * @Version:
 */
@Controller
@RequestMapping("/statics")
public class StaticsController {
    @Autowired
    private StaticsService staticsService;
    @RequestMapping("/index")
    public String index(Model model){
        return "statics/index";
    }

    @ResponseBody
    @RequestMapping("/ys/money/info")
    public String ysMoneyInfo(Model model,@RequestParam(defaultValue = "")String beginTime,
                              @RequestParam(defaultValue = "") String endTime){
        int dayTime = DateHandler.getDay();
        if(StringHandler.isEmpty(beginTime)){
            beginTime = dayTime+"";
            endTime = dayTime+"";
        }
        //支付统计
        Map<String,Object> payMap = staticsService.payInfo(0,StringHandler.getLong(beginTime),StringHandler.getLong(endTime));
        //支付统计--汇聚银行卡
        Map<String,Object> payYhkMap = staticsService.payInfo(5,StringHandler.getLong(beginTime),StringHandler.getLong(endTime));

        //支付统计--银盛银行卡
        Map<String,Object> payYsYhkMap = staticsService.payInfo(1,StringHandler.getLong(beginTime),StringHandler.getLong(endTime));
        //支付统计--支付宝
        List<ZfbMoneyInfo> payZfb = staticsService.pzyZfbList(StringHandler.getLong(beginTime),StringHandler.getLong(endTime));
        List<ZfbMoneyInfoVo> payZfbVo = new ArrayList<>();
        for (ZfbMoneyInfo zfbMoneyInfo:payZfb) {
            payZfbVo.add(zfbMoneyInfo.toVo());
        }
        beginTime = beginTime+"000000";
        endTime = endTime+"235959";
        //提现现统计
        Map<String,Object> withdrawMap = staticsService.withdrawInfo(0,StringHandler.getLong(beginTime),StringHandler.getLong(endTime));
        //体现统计 汇聚银行卡
        Map<String,Object> withdrawYhkMap = staticsService.withdrawInfo(5,StringHandler.getLong(beginTime),StringHandler.getLong(endTime));
        //体现统计 银盛银行卡
        Map<String,Object> withdrawYsMap = staticsService.withdrawInfo(1,StringHandler.getLong(beginTime),StringHandler.getLong(endTime));
        //体现统计 支付宝
        List<ZfbMoneyInfo> withdrawZfb = staticsService.withdrawZfbList(StringHandler.getLong(beginTime),StringHandler.getLong(endTime));
        List<ZfbMoneyInfoVo> withdrawZfbVo = new ArrayList<>();
        for (ZfbMoneyInfo zfbMoneyInfo:withdrawZfb) {
            withdrawZfbVo.add(zfbMoneyInfo.toVo());
        }
        long zfbTotalAmount = staticsService.zfbTotalAmount();
        int zfbTotalUser = staticsService.zfbTotalUser();
        long bankTotalAmount = staticsService.bankTotalAmount();
        int bankTotalUser = staticsService.bankTotalUser();
        StaticsVo staticsVo = new StaticsVo(payMap,withdrawMap,zfbTotalAmount,zfbTotalUser,bankTotalAmount,bankTotalUser,payYhkMap,withdrawYhkMap,payYsYhkMap,withdrawYsMap);
        staticsVo.payZfb = payZfbVo;
        staticsVo.withdrawZfb = withdrawZfbVo;
        staticsVo.beginTime = beginTime;
        staticsVo.endTime = endTime;
        Map<String,Object> result = ResultUtil.result();
        result.put("data",staticsVo);
        return ResultUtil.toJSON(result);
    }
}
